import { execSync } from 'child_process'
import chalk from 'chalk'
import { buildCommandsFn } from './constant.js'
async function build(answers) {
    console.log(chalk.green('开始打包'));
    const { project, env, dirPath } = answers;
    const buildCommands = buildCommandsFn(answers)    
    for (let i = 0; i < buildCommands.length; i++) {
        try {
            execSync(buildCommands[i].command, { stdio: 'inherit' });
            console.log(chalk.green(`打包成功 ${buildCommands[i].name}`));
        } catch (error) {
            console.log(chalk.red(`打包 ${buildCommands[i].name} 时出错：`, error.message));
            process.exit(1);
        }
    }
}
export default build